package com.vst.serverdatalib.entity;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import android.text.TextUtils;

public class V2TVBack {

    public String mTitle;

    public int mPlaydate;

    public String mLiveurl;

    public ArrayList<BackItem> mBackItems;

    public V2TVBack(String json) {
        if (TextUtils.isEmpty(json)) {
            return;
        }
        try {
            JSONObject jsonObject = new JSONObject(json);
            this.mTitle = jsonObject.optString("title");
            this.mPlaydate = jsonObject.optInt("playdate");
            this.mLiveurl = jsonObject.optString("liveurl");
            this.mBackItems = new ArrayList<V2TVBack.BackItem>();
            BackItem backItem;
            JSONArray jsonArray = jsonObject.optJSONArray("tvback");
            for (int i = 0; i < jsonArray.length(); i++) {
                backItem = new BackItem(jsonArray.opt(i).toString());
                mBackItems.add(backItem);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer("V2TVBack: mTitle= ");
        sb.append(mTitle).append(",mPlaydate = ").append(mPlaydate).append(",mLiveurl = ").append(mLiveurl)
                .append(",mBackItems = ").append(mBackItems);
        return sb.toString();
    }

    class BackItem {

        public String mTime;

        public String mName;

        public String mLink;

        public BackItem(String json) {
            if (TextUtils.isEmpty(json)) {
                return;
            }
            try {
                JSONObject jsonObject = new JSONObject(json);
                this.mTime = jsonObject.optString("time");
                this.mName = jsonObject.optString("name");
                this.mLink = jsonObject.optString("link");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public String toString() {
            StringBuffer sb = new StringBuffer("BackItem: mTime= ");
            sb.append(mTime).append(",mName = ").append(mName).append(",mLink = ").append(mLink);
            return sb.toString();
        }
    }

}
